package com.ruoyi.web.core.utils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;
import java.util.UUID;

/* loaded from: StringUtils.class */
public final class StringUtils extends org.apache.commons.lang3.StringUtils {
    private static final String INT_TEMP = "0123456789";
    private static final String STR_TEMP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final String ALL_TEMP = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    private static final Random RANDOM   = new Random();

    public static String encode(String str) {
        String encode = null;
        try {
            encode = URLEncoder.encode(str, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return encode;
    }

    public static String generateStr() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String getOutTradeNo() {
        return (new SimpleDateFormat("MMddHHmmss", Locale.getDefault()).format(new Date()) + System.currentTimeMillis()).substring(0, 15);
    }

    public static String format(String s, Object... args) {
        return MessageFormat.format(s, args);
    }

    public static String replace(String str, String regex, String... args) {
        for (String str2 : args) {
            str = str.replaceFirst(regex, str2);
        }
        return str;
    }

    public static String cleanChars(String txt) {
        return txt.replaceAll("[ 　\t`·•�\u0001\\f\\t\\v]", "");
    }

    public static String random(int count, RandomType randomType) {
        if (count == 0) {
            return "";
        }
        if (count < 0) {
            throw new IllegalArgumentException("Requested random string length " + count + " is less than 0.");
        }
        char[] buffer = new char[count];
        for (int i = 0; i < count; i++) {
            if (randomType.equals(RandomType.INT)) {
                buffer[i] = INT_TEMP.charAt(RANDOM.nextInt(INT_TEMP.length()));
            }
            else if (randomType.equals(RandomType.STRING)) {
                buffer[i] = STR_TEMP.charAt(RANDOM.nextInt(STR_TEMP.length()));
            }
            else {
                buffer[i] = ALL_TEMP.charAt(RANDOM.nextInt(ALL_TEMP.length()));
            }
        }
        return new String(buffer);
    }

    public static void main(String[] args) {
        System.out.println(random(32, RandomType.ALL));
    }

    /* loaded from: StringUtils$RandomType.class */
    public enum RandomType {
        INT,
        STRING,
        ALL
    }
}
